import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import routes from "./routes";
const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior: () => ({ left: 0, top: 0 }),
})
router.beforeEach((to, from, next) => {
  // console.log('---to---', to);
  // console.log('---from---', from);
  // console.log('---next---', next);
  if(to.query.token){
    localStorage.setItem("token", to.query.token)
  }
  const token = localStorage.getItem('token');
  const needLogin = to.matched.some((record) => record.meta.needLogin);
  // 可以增加更多的判读来处理路由跳转
  if (needLogin && !token) {
    if(to.fullPath === '/') {
    }else {
    }
  } else {
    next();
  }
});

export default router;
